﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using WebApi_ProductText1.Domain.Entity;

namespace WebApi_ProductText1.Domain
{
    public class DbinitializeHelper
    {
        // Initilzer：初始化器
        public static void Initilzer()
        {
            // 添加用户 
            using (var db = new Sell10000Context())
            {
                var dbExist = db.Database.EnsureCreated();
                var user = new User
                {
                    UserName = "烟雨过",
                    Password = "123456",
                    UserPhone = "12345678901",
                    Email = "1235@ab.com",
                    IDnumber = "1234567365862385632",
                    Name = "张三",
                    NickName = "三三三"
                };

                db.Users.Add(user);
                db.SaveChanges();


                var suplier1 = new Supplier
                {
                    SupplierName = "苹果",
                    ContactPerson = "xxxx",
                    SupplierPhone = "1234567"
                };
                var suplier2 = new Supplier
                {
                    SupplierName = "华为",
                    ContactPerson = "aaa",
                    SupplierPhone = "1234567"
                };
                var suplier3 = new Supplier
                {
                    SupplierName = "小米",
                    ContactPerson = "ccc",
                    SupplierPhone = "1234567"
                };

                db.Suppliers.AddRange(suplier1, suplier2, suplier3);
                db.SaveChanges();


                var product1 = new Product
                {
                    ProductName = "Apple",
                    ProductCategory = "手机",
                    ProductDescription = "苹果",
                    SupplierId = suplier1.Id,
                    Weight = "300g",
                    price = 5000m
                };
                var product2 = new Product
                {
                    ProductName = "华为",
                    ProductCategory = "手机",
                    ProductDescription = "国产",
                    SupplierId = suplier2.Id,
                    Weight = "300g",
                    price = 6000m
                };
                var product3 = new Product
                {
                    ProductName = "小米",
                    ProductCategory = "手机",
                    ProductDescription = "米米米",
                    SupplierId = suplier3.Id,
                    Weight = "300g",
                    price = 6000m
                };
                db.Products.AddRange(product1, product2, product3);
                db.SaveChanges();

                var orderforms = new Orderform()
                {
                    OrderNumber = "123",
                    UserId = user.Id,
                    ProductCategory = "15栋522",
                    ProductId = product1.Id,
                    ExpiryDate = 1,
                    price = product1.price * 1,
                    OrderStatus = "发货",
                    PaymentStatus = "已支付"
                };
                db.Orderforms.Add(orderforms);
                db.SaveChanges();

                var shoppingtrolley = new ShoppingTrolley()
                {
                    UserId = user.Id,
                    ProductId = product2.Id,
                    ItemQuantity = 3
                };
                db.ShoppingTrolleys.Add(shoppingtrolley);
                db.SaveChanges();


            }
        }
    }
}
